package edu.hunau.cxb19.oop.class32.tcp.v4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author hb
 *
 *         2020-04-21 16:23:09
 */
public class ServerTcp {
	private ServerSocket serverSocket;

	public ServerTcp() {
		try {
			serverSocket = new ServerSocket(8088);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void start() {
		System.out.println("等待客户端的连接....");
		try {
			Socket socket = serverSocket.accept();
			System.out.println("客户端已经连接!");
			// 读取客户端的消息
			InputStream is = socket.getInputStream();
			InputStreamReader isr = new InputStreamReader(is, "utf-8");
			BufferedReader br = new BufferedReader(isr);
			 
			while(true) {
				System.out.println(br.readLine());
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		ServerTcp server = new ServerTcp();
		server.start();
	}
}
